﻿using System.IO;
using Nett;

//test
namespace KaroglanLauncher
{
    public class Config//:ITomlMetadataProvider
    {
        public static string cfgPath = "./config.toml";
        public string version { get; set; } = "1.0.0";
        public string workSpace { get; set; } = "";

        public static Config Load()
        {
            if (File.Exists(cfgPath))
            {
                return Toml.ReadFile<Config>(cfgPath);
            }
            else
            {
                var result = new Config();
                result.Save();
                return result;
            }
        }

        public void Save()
        {
            var toml = Toml.Create(this);
            toml["version"]
                .AddComment(new TomlComment("######################################################################################", CommentLocation.Prepend))
                .AddComment(new TomlComment("                                       IMPORTANT                                     #", CommentLocation.Prepend))
                .AddComment(new TomlComment("######################################################################################", CommentLocation.Prepend))
                .AddComment(new TomlComment("       Do NOT modify this file, as it may cause DAMAGE to the launcher module.       #", CommentLocation.Prepend))
                .AddComment(new TomlComment("######################################################################################", CommentLocation.Prepend));
            Toml.WriteFile(toml, cfgPath);
        }
    }
}
